package ${filePackageName};

import ${annotationPackage}.SubmitValid;
import ${annotationPackage}.SysLog;
import ${commonBeanPackage}.ApiResult;
import ${enumsPackage}.EnumCode;
import ${commonBeanPackage}.Page;
import ${entityPackage}.${upperEntityName};
import ${listDtoPackage}.${upperEntityName}ListDto;
import ${voPackage}.${upperEntityName}Vo;
import ${servicePackage}.${upperEntityName}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * ${tableComment}
 * 
 * @author ${projectAuthor}
 * @version 1.0
 * @date ${nowDate}
 */
@Api(tags="${tableComment}")
@ApiSupport(author = "${projectAuthor}",order = 1)
@RequestMapping(value = "${accessBaseUrl}")
@RestController
public class ${upperEntityName}Controller extends BaseController{

	@Resource
	private ${upperEntityName}Service ${lowerEntityName}Service;

	@ApiOperation(value="分页查询${tableComment}")
	@GetMapping(value = "/${lowerEntityName}s", produces = MediaType.APPLICATION_JSON_VALUE)
	public ApiResult<Page<${upperEntityName}Vo>> pageList(${upperEntityName}ListDto ${lowerEntityName}ListDto) {
		return ApiResult.page(${lowerEntityName}Service.selectPage(${lowerEntityName}ListDto));
	}

	@ApiOperation(value="查询单个${tableComment}")
	@GetMapping(value = "/${lowerEntityName}/{${lowerPrimaryKey}}", produces = MediaType.APPLICATION_JSON_VALUE)
	public ApiResult<${upperEntityName}Vo> selectById(@PathVariable ${primaryType} ${lowerPrimaryKey}) {
		return ApiResult.data(${lowerEntityName}Service.selectById(${lowerPrimaryKey}));
	}

	@SubmitValid
	@ApiOperation(value="新增${tableComment}")
	@SysLog(operateType="新增${tableComment}")
	@PostMapping(value = "/${lowerEntityName}",produces = MediaType.APPLICATION_JSON_VALUE)
	public ApiResult insert(@RequestBody ${upperEntityName} ${lowerEntityName}){
		${lowerEntityName}Service.insert(${lowerEntityName});
		return ApiResult.success(EnumCode.INSERT_SUCCESS, ${lowerEntityName}.get${upperPrimaryKey}());
	}

	@SubmitValid
	@ApiOperation(value="修改${tableComment}")
	@SysLog(operateType="修改${tableComment}")
	@PutMapping(value = "/${lowerEntityName}", produces = MediaType.APPLICATION_JSON_VALUE)
	public ApiResult update(@RequestBody ${upperEntityName} ${lowerEntityName}) {
		${lowerEntityName}Service.update(${lowerEntityName});
		return ApiResult.success(EnumCode.UPDATE_SUCCESS);
	}

	@SubmitValid
	@ApiOperation(value="删除${tableComment}")
	@SysLog(operateType="删除${tableComment}")
	@DeleteMapping(value = "/${lowerEntityName}/{${lowerPrimaryKey}}", produces = MediaType.APPLICATION_JSON_VALUE)
	public ApiResult deleteOne(@PathVariable ${primaryType} ${lowerPrimaryKey}){
		${lowerEntityName}Service.delete(${lowerPrimaryKey});
		return ApiResult.success(EnumCode.DELETE_SUCCESS);
	}

	@SubmitValid
	@ApiOperation(value="批量删除${tableComment}")
	@SysLog(operateType="批量删除${tableComment}")
	@DeleteMapping(value = "/${lowerEntityName}s", produces = MediaType.APPLICATION_JSON_VALUE)
	public ApiResult deleteBatch(@RequestBody ArrayList<${primaryType}> ${lowerPrimaryKey}s){
		${lowerEntityName}Service.delete(${lowerPrimaryKey}s.toArray(new ${primaryType}[0]));
		return ApiResult.success(EnumCode.DELETE_SUCCESS);
	}
}